﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _12_DataGridView
{
    public partial class Frm_EditorProduct : Form
    {

        public Product product { get; set; }

        public Frm_EditorProduct()
        {
            InitializeComponent();
        }

        public Frm_EditorProduct(Product product)
        {
            InitializeComponent();
            this.textBox1.Text = product.ProductID.ToString();
            this.textBox2.Text = product.ProductName;
            this.comboBox1.SelectedItem = product.ProductQualified ? "合格" : "不合格";
            this.comboBox2.SelectedItem = product.ProductLineID.ToString();
        }

        /// <summary>
        /// 确认
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            product = new Product();//实例化对象
            product.ProductID = int.Parse(this.textBox1.Text);
            product.ProductName = this.textBox2.Text;
            product.ProductQualified = this.comboBox1.SelectedItem.ToString() == "合格"? true:false;
            product.ProductLineID =  int.Parse(this.comboBox2.SelectedItem.ToString());

            this.DialogResult = DialogResult.OK;

        }
        /// <summary>
        /// 取消
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }
    }
}
